package com.leyou.controller;

import com.leyou.enums.EnumException;
import com.leyou.exception.MyException;
import com.leyou.item.pojo.Item;
import com.leyou.service.ItemSerivice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文件名：
 * 描述：
 * 作者：梁帆
 * 时间：2018/11/6
 * 版权：
 */

@RestController
@RequestMapping("item")
public class ItemController {


    @Autowired
    private ItemSerivice mItemSerivice;


    @PostMapping
    public ResponseEntity<Item> saveItem(Item item){
        item = mItemSerivice.saveItem(item);
        if(item.getPrice() == null){
            throw new MyException(EnumException.PRICE_NOT_NULL);
        }
        ResponseEntity<Item> test_data = ResponseEntity.status(200).body(item);
        return test_data;
    };

}
